package com.ipet.app.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.ipet.app.R;
import com.ipet.app.adapter.ViewHolder.PostHotViewHolderImg;
import com.ipet.app.adapter.ViewHolder.PostHotViewHolderNormal;
import com.ipet.app.bean.HotPost;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;


/**
 * Created by jindongping on 16/3/17.
 */
public class FragmentOneAdapter extends RecyclerArrayAdapter<HotPost> {


    public final int TYPE_NORMAL = 1;
    public final int TYPE_NORMAL_IMG = 2;

    public FragmentOneAdapter(Context context) {
        super(context);
    }


    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case TYPE_NORMAL:
                return new PostHotViewHolderNormal(parent, R.layout.fragment_main_one_item_normal);
            case TYPE_NORMAL_IMG:
                return new PostHotViewHolderImg(parent, R.layout.fragment_main_one_item_img);
        }
        return new PostHotViewHolderImg(parent, R.layout.fragment_main_one_item_normal);
    }


    //目前只有一种视图 如果有多重 可以根据getItem(position) 来判断视图类型
    @Override
    public int getViewType(int position) {
        if (getItem(position).getPicurl() != null) {
            return TYPE_NORMAL_IMG;
        }
        return TYPE_NORMAL;
    }
}
